home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 25
/
Mac Magazin and MacEasy Magazine CD - Issue 25.iso
/
Grafik & Text
/
Alpha
/
Tcl
/
UserCode
/
smartModes.tcl
< prev
next >
Wrap
Text File
|
1996-08-15
|
3KB
|
98 lines
########################################################################
# Emacs-style mode selection using first nonblank line of file
#
# Checks for interpreter line "#!/dir/subdir/command ...", or
# explicit major mode election "-*-Mode: vars ...-*-".
#
# "command" or "Mode" is compared (case-insensitively) to Alpha mode
# names and first matching mode is used for the file.
#
# Author: Tom Pollard <pollard@chem.columbia.edu>
# Modified: 9/11/95
#
set emacsMode(rmail) {Mail}
set emacsMode(fortran) {Fort}
set emacsMode(latex) {TeX}
set emacsMode(pascal) {Pasc}
set emacsMode(matlab) {MATL}
set emacsMode(latex) {TeX}
proc checkModeLine {name} {
global modes winModes emacsMode
set modePat {\-\*\- *([^ :;]+).*\-\*\-}
set intPat {^#!([^ \n\r]+)}
bringToFront $name
set oldMode winModes($name)
set pos 0
set line [getText $pos [nextLineStart $pos]]
while {[regexp {^[ \n\r]*$} $line] && $pos != [maxPos]} {
set pos [nextLineStart $pos]
set line [getText $pos [nextLineStart $pos]]
}
if {$pos == [maxPos]} { return }
if {[regexp $modePat $line mtch majorMode]} {
} elseif {[regexp $intPat $line mtch majorMode] } {
if {![regexp {([^/]+)$} $mtch majorMode]} { return }
} else {
return
}
set majorMode [string tolower $majorMode]
# set imode [lsearch -exact [array names emacsMode] $majorMode]
# if {$imode >= 0} { #}
if {[catch {set winModes($name) $emacsMode($majorMode)}]} {
foreach m $modes {
if {[string tolower $m] == $majorMode} {
set winModes($name) $m
break
}
}
}
if {$winModes($name) != $oldMode} { bringToFront $name; centerRedraw }
}
# The following replaces the release version of "openHook" in "modes.tcl"
#
proc openHook name {
global winModes winActive autoMark mode screenHeight screenWidth forceMainScreen recentFiles recentFilesCount
checkModeLine $name
changeMode $winModes($name)
if {$name == {*Toolserver shell*}} startMPW
addWinName $name
message ""
if {![catch {getFileInfo $name info}]} {
if {$info(creator) == {ttxt}} {
setWinInfo dirty 0
}
if {$info(type) == {ttro}} {
catch {setWinInfo read-only 1}
message "Read-only!"
}
}
global ${mode}modeVars
if {$forceMainScreen} {
set geo [getGeometry]
set l [lindex $geo 0]; set t [lindex $geo 1]; set w [lindex $geo 2]; set h [lindex $geo 3];
if {($l < 0) || ($t < 35) || ([expr $l + $w] > $screenWidth) || ([expr $t + $h + 18] > $screenHeight)} {
singlePage
}
}
getWinInfo arr
if {[info exists ${mode}modeVars(autoMark)] && [set ${mode}modeVars(autoMark)] && !$arr(read-only) && ![llength [getNamedMarks -n]]} {
markFile
}
if {[string match "*Preferences*defs.tcl" $name]} {setWinInfo read-only 1}
pushRecent $name
}